<template>
   <div>
     <el-container>
       <el-header>Header</el-header>
       <el-main>
         <el-row>
           <el-col :span="8" >
             <el-upload
                 action="http://localhost:8800/upload/"
                 list-type="picture-card"
                 :on-preview="handlePictureCardPreview"
                 :on-remove="handleRemove"
ref="upload"
             :auto-upload="false"
             :on-success="onSuccess"
             :limit="1">
               <i class="el-icon-plus"></i>
             </el-upload>
             <el-dialog :visible.sync="dialogVisible">
               <img width="100%" :src="dialogImageUrl" alt="">
             </el-dialog>
<div class="btn">
  <input type="button" value="保存" class="yes" @click="submit2"/>
</div>

           </el-col>
           <el-col :span="8"><div class="grid-content bg-purple-light"></div></el-col>
           <el-col :span="8"><div class="grid-content bg-purple"></div></el-col>
         </el-row>

       </el-main>
       <el-footer>Footer</el-footer>
     </el-container>


   </div>



</template>

<script>

export default {
  name: "TongueAnalysis",
  data(){
    return{
      file:'',
      dialogImageUrl: '',
      dialogVisible: false,
      imgUrl:'',
    }
  },
  methods:{
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },

    // 点击保存按钮上传图片
    submit2:function(res){
      this.$refs.upload.submit();
    },

    // 图片上传成功后，后台返回图片的路径
    onSuccess:function(res){
      console.log(res);
      if(res.status==200){
        this.imgUrl=res.data.imgUrl;
      }
    }
  }
}
</script>

<style scoped>
.avatar-uploader {
  margin-top: 20px;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  width: 178px;
  height: 178px;
}

.avatar-uploader:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: flex;
}
</style>
